package com.ykqx.weather.service;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.ykqx.weather.dao.FYLZDao;
import com.ykqx.weather.dto.FYLZ;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2017/9/4 0004
 */
@Service
public class FYLZService {
    Gson gson = new GsonBuilder().create();
    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired

    FYLZDao fylzDao;
    public String getFYLZ(){
        FYLZ fylz = null;
        try {
            fylz = fylzDao.getFYLZ();
        } catch (Exception e) {
            logger.error("负氧离子数据请求失败->{}",e.getMessage());
            e.printStackTrace();
        }
        return gson.toJson(fylz);
    }

    public String getFYLZ24(){
        List<FYLZ> fylzList=new ArrayList<>();
        try {
            fylzList = fylzDao.getFYLZ24();
        } catch (Exception e) {
            logger.error("负氧离子数据请求失败->{}",e.getMessage());
            e.printStackTrace();
        }
        return gson.toJson(fylzList);
    }
}
